<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   template="/WEB-INF/templates/default.xhtml">
   
    <f:metadata>
	   	<f:viewParam name="serviceSupplierId" value="#{serviceSupplierHome.id}"></f:viewParam>	   	
	   	<f:event listener="#{serviceSupplierHome.initConversation()}" type="preRenderView"></f:event>
	   	<f:viewParam name="moduleName" value="中介用户管理"></f:viewParam>
   	</f:metadata>
   
    <ui:define name="content">
   
	   <h:form id="editForm">         
	        <p:messages id="messages" closable="true">
	       		<p:autoUpdate />
	       	</p:messages>
   			<p:panel id="baseInfo" header="修改中介用户" style="margin-bottom:10px;">		        
		        <h:panelGrid columns="2" cellpadding="5">
		        	<p:outputLabel
						for="cnname"
						value="公司名称"
					/>
					<p:inputText
						id="cnname"
						value="#{serviceSupplierHome.instance.cnname}"
						required="true"
						styleClass="input-large"
					/>
					
					<p:outputLabel
						for="registeredFund"
						value="注册资金(万元)"
					/>
					<p:inputText
						id="registeredFund"
						value="#{serviceSupplierHome.instance.registeredFund}"
						required="true"
						styleClass="input-small"
					/>
	        		
        			<p:outputLabel
						for="registrationAuthority"
						value="注册登记机关"
					/>
					<p:inputText
						id="registrationAuthority"
						value="#{serviceSupplierHome.instance.registrationAuthority}"
						required="true"
						styleClass="input-large"
					/>

					<p:outputLabel
						for="registrationNo"
						value="注册登记号"
					/>
					<p:inputText
						id="registrationNo"
						value="#{serviceSupplierHome.instance.registrationNo}"
					/>

					<p:outputLabel
						for="regtime"
						value="成立时间"
					/>
					<p:calendar
						id="regtime"
						value="#{serviceSupplierHome.instance.regtime}"
						required="true"
						pattern="yyyy-MM-dd"
						navigator="true"
						locale="zh_CN"
						inputStyleClass="input-small"
						showOn="button"
					/>
        		
					<p:outputPanel>
						<p:outputLabel
							for="businessLicenseImageUpload"
							value="营业执照"
						/>
						<br />
						（扫描图片上传）
					</p:outputPanel>
					<p:outputPanel >
						<p:fileUpload
							id="businessLicenseImageUpload"
							mode="advanced"
							skinSimple="true"
							required="true"
							invalidSizeMessage="必须上传一张图片，大小不能超过3M!"					
							allowTypes="/(\.|\/)(jpe?g|png)$/"
							sizeLimit="#{1024 * 1024 * 3}"
							uploadLabel="上传"
							cancelLabel="取消"
							update="editForm:businessLicenseImage"
							fileUploadListener="#{serviceSupplierHome.uploadBusinessLicenseImage}"
						></p:fileUpload>
						<p:panel
							id="businessLicenseImage">
							<p:outputLabel rendered="#{serviceSupplierHome.instance.businessLicenseImages.size() > 0}"  >
								<div id="imgsPreview" >
									<img  data-original="#{attachmentUtils.getFullPath(serviceSupplierHome.instance.businessLicenseImages[0])}" src="#{attachmentUtils.getFullPath(serviceSupplierHome.instance.businessLicenseImages[0])}"  id="img" width="240"/>
									<p:commandLink styleClass="closeBtn" action="#{serviceSupplierHome.removeBussinessImage()}"  update="editForm:businessLicenseImage" immediate="true" ></p:commandLink>
								</div>
							</p:outputLabel>
						</p:panel>
					</p:outputPanel>
					
					<ui:remove>
						<p:outputPanel>
							<p:outputLabel
								for="taxProveImagesUpload"
								value="纳税证明"
							/>
							<br />
							（扫描图片上传）
						</p:outputPanel>
						<p:outputPanel>												
							<p:fileUpload
								id="taxProveImagesUpload"
								label="选择"
								mode="advanced"
								multiple="true"
								skinSimple="true"
								sizeLimit="#{1024 * 1024 * 3}"
								uploadLabel="上传"
								cancelLabel="取消"
								update="editForm:taxProveImageList"
								fileUploadListener="#{serviceSupplierHome.uploadTaxProveImages}"
								allowTypes="/(\.|\/)(jpe?g|png)$/"
							/>
							<p:panel
								id="taxProveImageList"
								widgetVar="taxProveImageList">
								<p:dataList
									value="#{serviceSupplierHome.instance.taxProveImages}"
									var="_taxImage"
									rendered="#{serviceSupplierHome.instance.taxProveImages.size() > 0}"
									itemStyleClass="photoItem"
									varStatus="_certPhotoStatus"
								>
									<img  data-original="#{attachmentUtils.getFullPath(_taxImage)}" src="#{attachmentUtils.getFullPath(_taxImage)}"  id="img" width="240"/>
									
									<p:commandLink styleClass="closeBtn" action="#{serviceSupplierHome.removeTaxImage(_taxImage)}" update="editForm:taxProveImageList" immediate="true" ></p:commandLink>
								</p:dataList>
								<div style="clear: both" />
							</p:panel>
						</p:outputPanel>
					</ui:remove>
					<p:outputLabel
						for="creditCode"
						value="统一社会信用代码"
					/>
					<p:inputText
						id="creditCode"
						value="#{serviceSupplierHome.instance.creditCode}"
						required="true"
						styleClass="input-large"
					/>
	
					<p:outputLabel
						for="address"
						value="办公地址"
					/>
					<p:inputText
						id="address"
						value="#{serviceSupplierHome.instance.address}"
						required="true"
						styleClass="input-xlarge"
					/>

					<p:outputLabel
						for="legalPerson"
						value="法定代表人"
					/>
					<p:inputText
						id="legalPerson"
						value="#{serviceSupplierHome.instance.legalPerson}"
						required="true"
						styleClass="input-mini"
					/>

					<p:outputLabel
						for="legalPersonPhoneNumber"
						value="法定代表人联系电话"
					/>
					<p:inputText
						id="legalPersonPhoneNumber"
						value="#{serviceSupplierHome.instance.legalPersonPhoneNumber}"
						required="true"
						styleClass="input-small"
					/>

					<p:outputLabel
						for="firstContactor"
						value="第一联系人"
					/>
					<p:inputText
						id="firstContactor"
						value="#{serviceSupplierHome.instance.firstContactor}"
						required="true"
						styleClass="input-mini"
					/>

					<p:outputLabel
						for="firstContactorPhoneNumber"
						value="第一联系人电话"
					/>
					<p:inputText
						id="firstContactorPhoneNumber"
						value="#{serviceSupplierHome.instance.firstContactorPhoneNumber}"
						required="true"
						styleClass="input-small"
					/>

					<p:outputLabel
						for="secondContactor"
						value="第二联系人"
					/>
					<p:inputText
						id="secondContactor"
						value="#{serviceSupplierHome.instance.secondContactor}"
						styleClass="input-mini"
						required="true"
					/>

					<p:outputLabel
						for="secondContactorPhoneNumber"
						value="第二联系人电话"
					/>
					<p:inputText
						id="secondContactorPhoneNumber"
						value="#{serviceSupplierHome.instance.secondContactorPhoneNumber}"
						styleClass="input-small"
						required="true"
					/>

					<p:outputLabel
						for="employeeCount"
						value="员工数"
					/>
					<p:inputText
						id="employeeCount"
						value="#{serviceSupplierHome.instance.employeeCount}"
						styleClass="input-mini"
						required="true"
					/>

					<p:outputLabel
						for="highTitleEmployeeCount"
						value="高级职称人数"
					/>
					<p:inputText
						id="highTitleEmployeeCount"
						value="#{serviceSupplierHome.instance.highTitleEmployeeCount}"
						styleClass="input-mini"
						required="true"
					/>

					<p:outputLabel
						for="mediumTitleEmployeeCount"
						value="中级职称人数"
					/>
					<p:inputText
						id="mediumTitleEmployeeCount"
						value="#{serviceSupplierHome.instance.mediumTitleEmployeeCount}"
						styleClass="input-mini"
						required="true"
					/>

					<p:outputLabel
						for="beginnerTitleEmployeeCount"
						value="初级职称人数"
					/>
					<p:inputText
						id="beginnerTitleEmployeeCount"
						value="#{serviceSupplierHome.instance.beginnerTitleEmployeeCount}"
						styleClass="input-mini"
						required="true"
					/>

					<p:outputLabel
						for="govServiceSupplier"
						value="是否政府服务供应商"
					/>
					<p:selectBooleanCheckbox
						id="govServiceSupplier"
						value="#{serviceSupplierHome.instance.govServiceSupplier}"
					/>
					
					<p:outputLabel
						for="alwaysValid"
						value="营业期限"
					/>
					<p:selectOneRadio
						id="alwaysValid"
						value="#{serviceSupplierHome.instance.alwaysValid}"
						required="true"
					>
						<f:selectItem
							itemLabel="填写营业期限"
							itemValue="false"
							
						/>
						<f:selectItem
							itemLabel="长期有效"
							itemValue="true"
						/>
					</p:selectOneRadio>
					
					

					<p:outputLabel
						for="busnissAllotedTime"
						value="输入期限"
					/>
					<p:calendar
						id="busnissAllotedTime"
						value="#{serviceSupplierHome.instance.busnissAllotedTime}"
						pattern="yyyy-MM-dd"
						navigator="true"
						inputStyleClass="input-small"
						showOn="button"
					/>
					
					<p:outputLabel
						for="region"
						value="中介机构所在地区"
					/>
					<p:selectOneMenu id="region"
									 value="#{serviceSupplierHome.instance.region}"
									 required="true">
						<f:selectItem itemLabel="请选择" itemValue="#{null}"  />
						<f:selectItems value="#{codeDicUtils.getCodeDicList('所在地区')}" var="_codeDic" itemValue="#{_codeDic.codeValue}"
									   itemLabel="#{_codeDic.codeName}" />
					</p:selectOneMenu>
					
					<p:outputLabel
						for="intro"
						value="机构简介"
					/>
					<p:inputTextarea
						id="intro"
						value="#{serviceSupplierHome.instance.intro}"
						rows="5"
						styleClass="input-xlarge"
						required="true"
					/>
				</h:panelGrid>
			</p:panel>
			
			<p:remoteCommand name="updateBussinessPanel" immediate="true" update="businesses"></p:remoteCommand>
			<p:panel
				id="businesses"
				header="主营业务"
				widgetVar="businesses"
				style="margin-bottom:10px;"
				styleClass="nureg-cont nuregcbox nuregcboxsty">
				<c:forEach
					items="#{serviceSupplierHome.instance.mainBusinesses}"
					var="_business"
					varStatus="_status">
					<div class="certs">

						<p:commandLink
							styleClass="removeButton"
							rendered="#{_status.index > 0}"
							immediate="true"
							action="#{serviceSupplierHome.removeBusiness()}"
							ajax="true"
							oncomplete="updateBussinessPanel()">
							<f:setPropertyActionListener
								value="#{_business}"
								target="#{serviceSupplierHome.currentBusiness}"></f:setPropertyActionListener>
							<f:setPropertyActionListener
								value="#{_business.bussinessIndex}"
								target="#{serviceSupplierHome.currentBusinessIndex}"></f:setPropertyActionListener>
						</p:commandLink>
						<h2>主营业务#{_status.index + 1}</h2>

						<h:panelGrid
							columns="2"
							cellpadding="5">
							<p:outputLabel
								for="agentServiceDetail#{_business.bussinessIndex}"
								value="服务事项" />
							<p:outputPanel>
								<p:inputText
									id="agentServiceDetail#{_business.bussinessIndex}"
									widgetVar="agentServiceDetail#{_business.bussinessIndex}"
									value="#{_business.agentService.name}"
									required="true"
									readonly="true"
									styleClass="input-xlarge" />
								<p:commandButton
									oncomplete="PF('chooseAgentServiceDialog').show();"
									value="选择"
									immediate="true"
									update="chooseAgentServiceDialog">
									<f:setPropertyActionListener
										value="#{_business}"
										target="#{serviceSupplierHome.currentBusiness}"></f:setPropertyActionListener>
									<f:setPropertyActionListener
										value="#{_business.bussinessIndex}"
										target="#{serviceSupplierHome.currentBusinessIndex}"></f:setPropertyActionListener>
								</p:commandButton>

							</p:outputPanel>

							<p:outputLabel
								for="commitOfTime#{_business.bussinessIndex}"
								value="服务时限承诺" />
							<p:inputText
								id="commitOfTime#{_business.bussinessIndex}"
								value="#{_business.commitOfTime}"
								required="true"
								styleClass="input-xlarge" />

							<p:outputLabel
								for="commitOfPrice#{_business.bussinessIndex}"
								value="服务收费承诺" />
							<p:inputText
								id="commitOfPrice#{_business.bussinessIndex}"
								value="#{_business.commitOfPrice}"
								required="true"
								styleClass="input-xlarge" />

							<p:outputLabel
								for="commitOfQuality#{_business.bussinessIndex}"
								value="服务质量承诺" />
							<p:inputText
								id="commitOfQuality#{_business.bussinessIndex}"
								value="#{_business.commitOfQuality}"
								required="true"
								styleClass="input-xlarge" />
						
						</h:panelGrid>
								
						<p:panel>
							<p:outputLabel for="uploadImages#{_business.bussinessIndex}" value="请选择图片"></p:outputLabel>
							<p:fileUpload
								id="uploadImages#{_business.bussinessIndex}"
								mode="advanced"
								multiple="true"
								sequential="true"
								skinSimple="true"
								allowTypes="/(\.|\/)(jpe?g|png)$/"
								invalidFileMessage="文件类型错误，请上传png或jpg格式的图片"
								sizeLimit="#{1024 * 1024 * 3}"
								invalidSizeMessage="文件大小不能超过3M!"
								uploadLabel="上传"
								cancelLabel="取消"
								update="editForm:uploadedImages#{_business.bussinessIndex}"
								fileUploadListener="#{serviceSupplierHome.uploadAgentServicePhotos}"></p:fileUpload>					
							
							<p:dataTable id="uploadedImages#{_business.bussinessIndex}" value="#{_business.images}" var="_attr" rowIndexVar="_row" emptyMessage="无已上传图片">
							
								<p:column headerText="文件名">
									<h:outputText value="#{_attr.filename}" />
								</p:column>
													
								<p:column headerText="大小（MB）" style="text-align: right;">
									<h:outputText value="#{_attr.filesize / 1024 / 1024}">	
										<f:convertNumber minFractionDigits="2" groupingUsed="true" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="预览">
									<img data-original="#{attachmentUtils.getFullPath( _attr )}" src="#{attachmentUtils.getFullPath( _attr )}" width="240"/>
								</p:column>
								
								<p:column headerText="操作">						
									<p:commandLink styleClass="closeBtn" value="删除" action="#{serviceSupplierHome.removeAgentServicePhoto(_status.index, _attr)}"  update="editForm:uploadedImages#{_business.bussinessIndex}" immediate="true" ></p:commandLink>
								</p:column>
								
							</p:dataTable>
						</p:panel>
					</div>
				</c:forEach>

				<p:commandButton
					action="#{serviceSupplierHome.instance.addEmptyBusiness()}"
					update="businesses"
					value="添加业务"
					immediate="true"></p:commandButton>
			</p:panel>
			
			
   			<p:commandButton action="#{serviceSupplierHome.saveAndFlush()}" value="保存" ajax="true" />  
   			<p:commandButton id="submitBtn" action="#{serviceSupplierHome.reSubmitAdmin()}" value="重新提交审核" ajax="true" />  
   			<p:tooltip id="toolTipGrow1" for="submitBtn" value="将中介重置为未审核状态！"
      									showEffect="clip" hideEffect="explode" position="bottom"/>
   			<p:commandButton action="#{serviceSupplierHome.delete()}" rendered="#{request.isUserInRole('developer')}" value="伪删除" ajax="true" /> 
   			<p:commandButton action="#{serviceSupplierHome.realDelete()}" rendered="#{request.isUserInRole('developer')}" value="真实删除" ajax="true" /> 			
			<p:commandButton action="#{serviceSupplierHome.cancel()}" value="取消" immediate="true"></p:commandButton>
	   	</h:form>
	   	
	   	<p:dialog
			id="chooseAgentServiceDialog"
			widgetVar="chooseAgentServiceDialog"
			width="666"
			height="600"
			modal="true"
		>
			<h:form>
				<p:panel>
					<f:facet name="header">选择服务事项</f:facet>
					
					<p:scrollPanel style="height: 450px; border: 0px;" mode="native" >
						 <p:dataTable var="_service"  value="#{agentServiceList.resultList}" rows="10"
                         paginator="true"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15"
                          selection="#{serviceSupplierHome.selectedAgentServiceMap[serviceSupplierHome.currentBusinessIndex]}" rowKey="#{_service.name}">                   
                          <p:column selectionMode="single" style="width:16px;text-align:center"/>
					        <p:column headerText="服务事项名称">
					            <h:outputText value="#{_service.name}" />
					        </p:column>
				        	<p:column headerText="对应资质大类">
					            <h:outputText value="#{_service.qualificationClass.name}" />
					        </p:column>
				        </p:dataTable>
					</p:scrollPanel>

					<f:facet name="footer">
						<p:commandButton
							value="确定"
							action="#{serviceSupplierHome.updateAgentService()}"
							update="editForm:agentServiceDetail#{serviceSupplierHome.currentBusinessIndex}"
							oncomplete="PF('chooseAgentServiceDialog').hide();"
						/>
						<p:commandButton
							value="取消"
							onclick="PF('chooseAgentServiceDialog').hide();"
						/>
					</f:facet>
				</p:panel>
			</h:form>
		</p:dialog>
   </ui:define>
   
</ui:composition>
